package me.zk.practice1.s;

import java.util.HashSet;
import java.util.Set;

/**
 * @author zhangkai
 * @date 2023/7/30 13:24
 */
public class LS128 {

    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        int maxLen = 0;
        for (int num : nums) {
            int longgest = 1;
            //判断是不是连续节点最小的数字
            if (!set.contains(num - 1)) {
                int pre = num + 1;
                while (set.contains(pre)) {
                    longgest++;
                    pre++;
                }

            }
            maxLen = Math.max(longgest,maxLen);
        }
        return maxLen;
    }
}
